<if condition="IS_AJAX">
	<volist name="list" id="vo">
        <div class="col-xs-12 span-hover task" data-id="{$vo.id}">
        	<span class="col-xs-5">{$vo.title}</span>
        	<span class="col-xs-2">{$vo.integralNum}</span>
        	<span class="col-xs-3">{$vo.creator_name}</span>
        	<span class="col-xs-2"><?= $vo['status']==1?'完成':'进行中' ?></span>
        </div>
    </volist>
<else/>
<include file="Public:header" /> <include file="Public:navgation" />
<div class="container-fluid main-content"> 
  <div class="page-title chart-container"> </div>
  

  
  <div class="row">
    <div class="col-md-12">
      <div class="widget-container">
            <div class="heading"> 
                <i class="icon-bar-chart"></i>任务管理
                <if condition="getAccessMenu($accessList, 'Intesys', 'Task', 'insert')"> 
                	<a class="btn pull-right f-fillwidth" onClick="addTask()" >添加</a> 
                </if>
            </div>  
        <div class="widget-content padded modal-open">
            <!-- Add code to initialize the tree when the document is loaded: -->
            <style type="text/css">
              /* Define custom width and alignment of table columns */
              #treetable {
                table-layout: fixed;
              }
            </style>
            <script type="text/javascript">
            	//树状列表的图标
              glyph_opts = {
                map: {
                  doc: "glyphicon glyphicon-folder-close",
                  docOpen: "glyphicon glyphicon-folder-open",
                  expanderClosed: "icon-angle-right",
                  expanderLazy: "icon-angle-right",  // glyphicon-plus-sign
                  expanderOpen: "icon-angle-down",  // glyphicon-collapse-down
                  loading: "glyphicon glyphicon-refresh glyphicon-spin"
                }
              };
			  //树状列表显示
              $(function(){
					$("#treetable").fancytree({
					  extensions: ["glyph", "table"],
					  glyph: glyph_opts,
					  source: {url: "__URL__/getTask", debugDelay: 1000},
					  table: {
						nodeColumnIdx: 1
					  },
					  activate: function(event, data) {
					  },
					  lazyLoad: function(event, data) {
						data.result = {url: "__URL__/getTask", debugDelay: 1000};
					  },
					  renderColumns: function(event, data) {
						var node = data.node,
						  $tdList = $(node.tr).find(">td");
						$tdList.eq(0).text(node.getIndexHier());
						$tdList.eq(2).text(node.data.integralNum);
						$tdList.eq(3).text(node.data.remark);
						$tdList.eq(4).text(node.data.executor_name);
						$tdList.eq(5).text(format(Number(node.data.datetime)));
						var look='<div class="text-center actions BottomOptionBtn"><a class="table-actions button" href="#" onClick="viewTask('+node.data.id+')"><i class="icon-eye-open"></i>查看</a>';
						var edit='<a class="table-actions update button" href="#" onClick="editTask('+node.data.id+')" ><i class="icon-pencil"></i>修改</a>';
						var dele='<a class="delete-row table-actions button" href="__URL__/delete/id/'+node.data.id+'" row="'+node.data.id+'"><i class="icon-trash"></i>删除</a></div>';
						$tdList.eq(6).html(look+edit+dele);
					  }
					});
              });
			  
            </script>
            <table id="treetable" class="table table-striped  dataTable DataListItem">
              <thead>
                <tr class="hidden-xs">
                  <th class="hidden-xs">节点</th>
                  <th>名称</th>
                  <th>积分</th>
                  <th class="hidden-xs">备注</th>
                  <th>执行人</th>
                  <th class="hidden-xs">时间</th>
                  <th class="hidden-xs"></th>
                </tr>
              </thead>
              <tr class="data_list">
              	<td class="hidden-xs"></td>
                <td></td>
                <td></td>
                <td class="hidden-xs"></td>
                <td></td>
                <td class="hidden-xs"></td>
                <td class="hidden-xs"></td> 
              </tr>
            </table>
         
        </div>

      </div>
    </div>
  </div>
</div>
<script>
$(".dataTable").on("click",".update",function(e) {
    e.preventDefault();
    $("#myModal3 form").attr("action",$(this).attr("href"));
    $("#myModal3 .form-group").find('[name="number"]').val($(this).parents(".data_list").find("td:eq(2)").html());
    $("#myModal3 .form-group").find('[name="date"]').val($(this).parents(".data_list").find("td:eq(4)").html());
    $("#myModal3 .form-group  #editorr #ueditor_0").contents().find("body p").html($(this).parents(".data_list").find("td:eq(3)").html());  
    var groupid=$(this).attr("data-groupid");
    var rewarderid=$(this).attr("data-rewarderid");
	
	//获取和设置奖惩人的部门
	$.getJSON("__GROUP__/Integral_rule/getmembergroup",{'id':rewarderid},function(data){
		if(data.statu!=1){return;}
		groupid=data.groupid
		$(".groupid").find("option[value='"+groupid+"']").attr("selected","selected");
		$.getJSON("__GROUP__/Integral_rule/getmember",{'groupid':groupid},function(data){
			if(data.statu!=1){return;}
			$(".memberid").html('<option value="">请选择</option>');
			$(data.member).each(function(index, element) {
				str=element['id']==rewarderid?"selected='selected'":"";
				$(".memberid").append('<option '+str+' value="'+element.id+'">'+element.name+'</option>');
			});
	   });			
	});
    $("#myModal3").modal("show");
    
});

$(".f-changetype").click(function(e) {
    $("#myModal4 [name='id']").val($(this).attr("data-id"));
	$("#myModal4").modal("show");
});
$(".dataTable").on("click","a.f-look",function(e){
    e.preventDefault();
	$("#fancybox ul").html("");
	var th=$(this).parents("table").find("thead tr th");
	console.log(th);
	$(this).parents("tr").find("td:not(:last)").each(function(index, element) {
		$("#fancybox ul").append("<p><span class='text-primary'>"+th.eq(index).text()+": </span>"+$(this).text()+"</p>");
	});
});

function addTask(){
	_openWindow('__URL__/add',500, '创建任务', '提交',function(){
		var form=$("#validate-form");
		$.post(form.attr("action"),form.serialize(),function(data){if(data.statu==0){console.log(data.info);}},'json');
		//刷新页面内容
		var tree=$("#treetable").fancytree("getTree");
		tree.reload();
	},'');	
}
function editTask(id){
	_openWindow('__URL__/edit/id/'+id,500, '修改任务', '提交',function(){
		var form=$("#validate-form");
		$.post(form.attr("action"),form.serialize(),function(data){if(data.statu==0){console.log(data.info);}},'json');
		//刷新页面内容
		var tree=$("#treetable").fancytree("getTree");
		tree.reload();
	},'');	
}
function viewTask(id){
	_openWindow('__URL__/view/id/'+id,500, '查看任务', '取消',function(){},'');	
}
function showMemberView(){
	_openWindow('__GROUP__/Member/getMemberGroup',500, '选择员工', '确定',setInputValue,'');
}
function showMemberRadioView(classname){
	var classname=classname||'executor_id';
	_openWindow('__GROUP__/Member/getMemberGroupRadio',500, '选择员工', '确定',function(){setInputValue(classname);},'');
}
function showRule(){
	_openWindow('__GROUP__/Integral_rule/getRuleView',500, '选择员工', '确定',function(){setInputValue('rule_id');},'');
}
//将窗口选中的选项设置到相应name的文本框中（一般当作回调函数来使用）
function setInputValue(name){
	var name=name||'memberid';
	var str="";
	var strname="";
	$(".f-view [name='input']:checked").each(function(index, element) {
		str+=","+$(this).val();
		strname+=","+$(this).next().text();
	});
	$(".f-fill"+name).val(strname.substr(1));
	$(".form-control[name='"+name+"']").val(str.substr(1));	
}
</script> 
<script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script> 
<include file="Public:footer" />
</if>